package com.turing.post.datatranfer.impl;

import java.math.BigInteger;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import com.turing.post.capitalaccounts.util.CapitalApplicationException;
import com.turing.post.cardmanagement.util.CardClassic;
import com.turing.post.cardmanagement.util.CardClassicDao;
import com.turing.post.common.util.ContrastDao;
import com.turing.post.datatranfer.util.CardkindBusiness;
import com.turing.post.datatranfer.util.CardkindDao;
import com.turing.post.datatranfer.util.TranferApplicationException;
import com.turing.post.util.PCPSApplicationException;
import com.turing.post.util.PCPSUtil;

/**
 * 卡控制业务实现接口
 * 
 * @author WZD
 */
@Stateless(mappedName = "datatranfer.impl.CardkindBusinessImpl")
@Remote
@Local
public class CardkindBusinessImpl implements CardkindBusiness {

	@EJB(mappedName = "datatranfer.impl.CardkindDaoImpl")
	private CardkindDao cardkindDaoImpl;
	@EJB(mappedName = "cardmanagement.impl.CardClassicDaoImpl")
	private CardClassicDao cardClassicDaoImpl;// 卡种类接口

	@EJB(mappedName = "common.impl.ContrastDaoImpl")
	private ContrastDao contrastDaoImpl;// 对照表接口
	public void insertCardClassic(String issuecompanyno) throws PCPSApplicationException{
		List<Object[]> list = cardkindDaoImpl.getCardkind();
		CardClassic cardClassic = null;
		Object[] obj = null;
		for (int i = 0; i < list.size(); i++) {
			obj = list.get(i);
			
			// 检查发卡商机构是否存在
			if (PCPSUtil.isEmpty(issuecompanyno)) {
				throw new CapitalApplicationException(
						TranferApplicationException.ERRCODE_CATEGORY_APPLICATION,
						"", "发卡商为空!");
			}	
			//System.out.println("老卡种类id="+obj[0].toString()+"----"+obj[1].toString());
			if(PCPSUtil.isEmpty(contrastDaoImpl.getMapCardClassicByNo(obj[0].toString()))){
				cardClassic = new CardClassic();
				cardClassic.setCardClassicName(obj[1].toString());
				cardClassic.setIssueCompanyNo(issuecompanyno);
				cardClassic.setStatus("0");
				cardClassic.setIsRealName("0");
				cardClassic.setAllowDeposit("0");
				cardClassic.setBalanceLimit(new BigInteger("0"));
				cardClassic.setPaidCountLimit(0);
				cardClassic.setPaidAmountLowLimit(0);
				cardClassic.setPaidAmountHighLimit(0);
				cardClassic.setAllowRedemp("0");
				cardClassic.setRemark(obj[2]==null?null:obj[1].toString());
				String cardclassid=cardClassicDaoImpl.insertCardClassic_Qy(cardClassic);
				
				contrastDaoImpl.insertMapCardClassic(obj[0].toString(), cardclassid);
			}
		}
	}
}
